package org.example.springbook.model;

import lombok.Data;
import org.example.springbook.constant.Constants;

@Data
public class Result <T>{
    private int code;
    private String errMsg;
    private T data;
    public static <T> Result success(T data){
        Result result = new Result();
        result.setCode(Constants.SUCCESS_CODE);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }
    public static <T> Result unlogin(){
        Result result = new Result();
        result.setCode(Constants.UNLOGIN_CODE);
        result.setErrMsg("用户未登录");
        return result;
    }
    public static <T> Result fail(T data){
        Result result = new Result();
        result.setCode(Constants.FAIL_CODE);
        result.setErrMsg("失败");
        return result;
    }
    public static <T> Result fail(){
        Result result = new Result();
        result.setCode(Constants.FAIL_CODE);
        result.setErrMsg("失败");
        return result;
    }
}
